<template>
  <div class="app-container">
    <!--查询-->
    <el-form :inline="true">

      <el-form-item label=" 信息内容">
        <el-input
          v-model="searchForm.mailMessage"
          placeholder=" 信息内容"
          clearable
          @blur="fetchList"
          @keyup.enter.native="fetchList"
        />
      </el-form-item>

      <el-form-item label=" 状态">
        <el-select
          v-model="searchForm.mailStatus"
          clearable
          @blur="fetchList"
          @keyup.enter.native="fetchList"
        >
          <el-option label="未读" value="0" />
          <el-option label="已读" value="1" />
        </el-select>
      </el-form-item>

      <search-buttons :fetch-data="fetchList" />
    </el-form>
    <!--表格-->
    <el-table :data="tableData" border stripe>
      <el-table-column type="index" width="50" label="序号" />
      <!--
        假设要将数据库中的数字变成对应的意思可以用下边的写法
         <el-table-column prop="sex" width="50" label="性别" >
            <template slot-scope="scope">
              <span v-if="scope.row.sex == '0'">女</span>
              <span v-if="scope.row.sex == '1'">男</span>
              <span v-if="scope.row.sex == '2'">保密</span>
            </template>
         </el-table-column>
      -->

      <el-table-column prop="mailMessage" label=" 信息内容" />
      <el-table-column prop="mailTo" label="接收人" />
      <el-table-column prop="mailStatus" label=" 状态">
        <template slot-scope="scope">
          <span v-if="scope.row.mailStatus == '0'">未读</span>
          <span v-if="scope.row.mailStatus == '1'">已读</span>
        </template>
      </el-table-column>

      <el-table-column label="操作" align="center">
        <template slot-scope="scope">
          <operation-buttons
            :row="scope.row"
            :del-fun="delSysSiteMailById"
            />
        </template>
      </el-table-column>
    </el-table>
    <div>
      <!-- 分页 -->
      <pagination
        :page.sync="searchForm.currentPage"
        :total="total"
        :limit.sync="searchForm.pageSize"
        @pagination="fetchList"
      />
    </div>
  </div>
</template>
<script>
import sysSiteMail from '@/api/siteMail'
import Pagination from '@/components/Pagination/index'
import SearchButtons from '@/components/SearchButtons/index'
import OperationButtons from '@/components/OperationButtons/index'
export default {
  components: {
    Pagination,
    SearchButtons,
    OperationButtons
  },
  data() {
    return {
      name: 'SysSiteMail',
      searchForm: {
        currentPage: 1,
        pageSize: 10
      },
      total: 0,
      tableData: []
    }
  },
  created() {
    this.fetchList()
  },
  methods: {
    fetchList() {
      sysSiteMail.fetchList({ ...this.searchForm }).then(resp => {
        this.tableData = resp.data.data
        this.total = resp.data.total
        this.searchForm.pageNum = resp.data.pageNum
        this.searchForm.currentPage = resp.data.currentPage
      })
    },
    delSysSiteMailById(id) {
      sysSiteMail.delById(id).then(resp => {
        this.$message.info(resp.message)
      })
    },
    clearSearchForm() {
      this.searchForm = {}
    },
    downloadTemplate() {
      window.location.href = 'http://localhost:9527/sysSiteMail/template'
    },
    export2Excel() {
      sysSiteMail.export2Excel({ ...this.searchForm })
    }
  }
}
</script>
<style>

</style>
